const express = require('express');
const expressStatic = require('express-static');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');


// let server = express();
// server.listen(8787);

// server.use(bodyParser.urlencoded({ //必须经过bodyParser加工才能获取到post数据
//    extended:false,      //扩展模式 true/false
//    limit: 2*1024*1024         //限制大小
     
// })); 

// server.use('/user',(req,res)=>{
//     console.log(req.body);
//     console.log(res);

// })

// server.use(expressStatic('./www')); //处理静态文件


// let server = express();

// server.use(cookieParser('wbcsddew')); //加密解析
// //cookie
// server.use('/',(req,res)=>{
//     req.secret='wbcsddew';   //密钥
//     res.cookie('user1','qiang',{signed:true});  //放在发送前面  signed:true cookie加密

//     console.log(req.signedCookies);
//     console.log(req.cookies);


//    res.send('22222222222');
  
// //    res.end();
// })
// server.listen(8780);


// session
let server = express();

let keys = ['aaa','bbb','ccc']; //全局密钥
server.use(cookieParser()); //加密解析
server.use(cookieSession(
    {name:'qiang',keys,maxAge:60*60*1000}
));

server.use('/',(req,res)=>{
       if(req.session['count'==null]){ //判断有没有
        req.session['count'] =1;
       }else{
        req.session['count'] ++;
       }

    console.log(req.session['count'])

   res.send('22222222222');
  
//    res.end();
})
server.listen(8780);